"""PAMR Train

.. helpdoc::
Train a PAMR Model.

"""


"""<widgetXML>
    <name>PAMR Train</name>
    <icon></icon>
    <tags>
        <tag>PAMR</tag>
    </tags>
    <summary>Train a PAMR data model.</summary>
    <author>
        <authorname>Red-R Core Development Team</authorname>
        <authorcontact>www.red-r.org</authorcontact>
    </author>
    </widgetXML>
"""

"""
<name>Train PAMR Model</name>
<author>Generated using Widget Maker written by Kyle R. Covington</author>
<tags>PAMR</tags>
"""
from OWRpy import * 
import OWGUI 
import redRGUI, signals

class pamr_train(OWRpy): 
    settingsList = []
    def __init__(self, **kwargs):
        OWRpy.__init__(self, **kwargs)
        self.setRvariableNames(["pamr.train"])
        self.require_librarys(["pamr"])
        
        """.. rrsignals::"""
        self.inputs.addInput("data", 'PAMR Data Collection', signals.pamr.RPAMRData, self.processdata)
        
        """.. rrsignals::"""
        self.inputs.addInput("gene_subset", 'Subset of Genes (optional)', signals.base.RVector, self.processgene_subset)
        
        """.. rrsignals::"""
        self.outputs.addOutput("pamr.train Output", 'Trained PAMR Model Fit', signals.pamr.RPAMRFit)
        
        self.RFunctionParam_gene_subset = ''
        self.RFunctionParam_data= ''
        
        box = redRGUI.base.tabWidget(self.controlArea)
        
        
        self.standardTab = box.createTabPage(name = "Standard", orientation = 'vertical')
        self.advancedTab = box.createTabPage(name = "Advanced", orientation = 'vertical')
        
        """.. rrgui::"""
        self.RFunctionParamngroup_survival_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "ngroup_survival:")
        
        """.. rrgui::"""
        self.RFunctionParamn_threshold_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "n_threshold:")
        
        """.. rrgui::"""
        self.RFunctionParamoffset_percent_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "offset_percent:")
        
        """.. rrgui::"""
        self.RFunctionParamhetero_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "hetero:")
        
        """.. rrgui::"""
        self.RFunctionParamremove_zeros_lineEdit =  redRGUI.base.lineEdit(self.standardTab,  label = "remove_zeros:")
        
        """.. rrgui::"""
        self.RFunctionParamsample_subset_lineEdit =  redRGUI.base.lineEdit(self.standardTab,  label = "sample_subset:")
        
        """.. rrgui::"""
        self.RFunctionParamse_scale_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "se_scale:")
        
        """.. rrgui::"""
        self.RFunctionParamscale_sd_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "scale_sd:")
        
        """.. rrgui::"""
        self.RFunctionParamprior_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "prior:")
        
        """.. rrgui::"""
        self.RFunctionParamthreshold_scale_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "threshold_scale:")
        
        """.. rrgui::"""
        self.RFunctionParamthreshold_lineEdit =  redRGUI.base.lineEdit(self.standardTab,  label = "threshold:")
        
        """.. rrgui::"""
        self.RFunctionParamsign_contrast_lineEdit =  redRGUI.base.lineEdit(self.advancedTab, label = "sign_contrast:")
        
        """.. rrgui::"""
        redRGUI.base.commitButton(self.controlArea, label="Commit", callback = self.commitFunction)
    def processdata(self, data):
        
        if data:
            self.RFunctionParam_data=str(data.getData())
        else:
            self.RFunctionParam_data= ''
    def processgene_subset(self, data):
        
        if data:
            self.RFunctionParam_gene_subset=str(data.getData())
        else:
            self.RFunctionParam_gene_subset = ''
    def commitFunction(self):
        if unicode(self.RFunctionParam_data) == '': return
        
        injection = []
        if unicode(self.RFunctionParam_gene_subset) != '':
            injection.append('gene.subset='+unicode(self.RFunctionParam_gene_subset))
        if unicode(self.RFunctionParamngroup_survival_lineEdit.text()) != '':
            string = 'ngroup_survival='+unicode(self.RFunctionParamngroup_survival_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamn_threshold_lineEdit.text()) != '':
            string = 'n_threshold='+unicode(self.RFunctionParamn_threshold_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamoffset_percent_lineEdit.text()) != '':
            string = 'offset_percent='+unicode(self.RFunctionParamoffset_percent_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamhetero_lineEdit.text()) != '':
            string = 'hetero='+unicode(self.RFunctionParamhetero_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamremove_zeros_lineEdit.text()) != '':
            string = 'remove_zeros='+unicode(self.RFunctionParamremove_zeros_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamsample_subset_lineEdit.text()) != '':
            string = 'sample_subset='+unicode(self.RFunctionParamsample_subset_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamse_scale_lineEdit.text()) != '':
            string = 'se_scale='+unicode(self.RFunctionParamse_scale_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamscale_sd_lineEdit.text()) != '':
            string = 'scale_sd='+unicode(self.RFunctionParamscale_sd_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamprior_lineEdit.text()) != '':
            string = 'prior='+unicode(self.RFunctionParamprior_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamthreshold_scale_lineEdit.text()) != '':
            string = 'threshold_scale='+unicode(self.RFunctionParamthreshold_scale_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamthreshold_lineEdit.text()) != '':
            string = 'threshold='+unicode(self.RFunctionParamthreshold_lineEdit.text())
            injection.append(string)
        if unicode(self.RFunctionParamsign_contrast_lineEdit.text()) != '':
            string = 'sign_contrast='+unicode(self.RFunctionParamsign_contrast_lineEdit.text())
            injection.append(string)
        inj = ','.join(injection)
        if inj != '':
            inj = ',' + inj
        self.R(self.Rvariables['pamr.train']+'<-pamr.train(data='+self.RFunctionParam_data+inj+')')
        newData = signals.pamr.RPAMRFit(self, data = self.Rvariables['pamr.train'], parent = self.RFunctionParam_data)
        self.rSend("pamr.train Output", newData)
        